import java.util.Stack;

public class Solution1261 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    TreeNode root;

    public Solution1261(TreeNode root) {
        this.root=root;
    }

    public boolean find(int target) {
        Stack<Integer> stack=new Stack<>();
        while (target>0){
            stack.add(target);
            if (target%2==1){
                target=(target-1)/2;
            }else {
                target=(target-2)/2;
            }
        }
        TreeNode treeNode=root;
        while (!stack.isEmpty()){
            int t=stack.pop();
            if (t%2==0){
                treeNode=treeNode.right;
            }else {
                treeNode=treeNode.left;
            }
            if (treeNode==null){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution1261 solution1261=new Solution1261(new TreeNode(-1,null,new TreeNode(-1)));
        System.out.println(solution1261.find(1));
        System.out.println(solution1261.find(2));
    }
}
